﻿using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using System;

namespace Twitter.Tests
{
    public abstract class TestBase
    {
        [SetUp]
        public virtual void SetUp()
        {
            if (Debugger.IsAttached)
            {
                Tracer.SetLoggingLevel(typeof(BotProcessor).Namespace, SourceLevels.Verbose);
                Tracer.AddListener(typeof(BotProcessor).Namespace, new ConsoleTraceListener());
            }
        }

        protected Message CreateMessage(string text, string sender, string recipient)
        {
            MessageTextNormalizer messageNormalizer = new MessageTextNormalizer();
            Message message = new Message
                            {
                                Id = Guid.NewGuid().ToString(),
                                Created = DateTime.Now,
                                Text = text,
                                Sender = new User
                                {
                                    Id = sender,
                                    Name = sender,
                                    ScreenName = sender
                                },
                                Recipient = new User
                                {
                                    Id = recipient,
                                    Name = recipient,
                                    ScreenName = recipient
                                }
                            };

            messageNormalizer.NormalizeWhitespaceAndCasing(message);
            return message;
        }

        /// <summary>
        /// IMessageBuilder that doesn't split messages.
        /// Useful for testing MessageProcessors.
        /// </summary>
        /// <returns></returns>
        protected IMessageBuilder CreateMessageBuilder()
        {
            return new PlainTextMessageBuilder(int.MaxValue);
        }
    }
}
